﻿using JFnetcore.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Utility;

namespace JFnetcore.Controllers
{
    public class BaseController : Controller
    {
        public SessionModel getUserSession()
        {
            string userJson = HttpContext.Session.GetString("JinFanUser");
            if (string.IsNullOrEmpty(userJson))
            {
                return null;
            }
            SessionModel userSession = JsonConvert.DeserializeObject<SessionModel>(userJson);
            return userSession;
        }

        //public override void OnActionExecuting(ActionExecutingContext filterContext)
        //{
        //    byte[] result;
        //    filterContext.HttpContext.Session.TryGetValue("JinFanUser", out result);
        //    if (result == null)
        //    {
        //        //filterContext.Result = Content(ReturnJsonHelp.BJUIajaxJson(301, "Session超时！", "", "", "", false, "", ""));
        //        filterContext.Result = new RedirectResult("/Login/LoginForm");
        //        return;
        //    }
        //    SessionModel userSession = getUserSession();
        //    if (userSession != null && userSession.User.Disable == 1)
        //    {
        //        base.OnActionExecuting(filterContext);
        //    }
        //    else
        //    {
        //        filterContext.Result = new RedirectResult("/Login/LoginForm");
        //        return;
        //    }
        //}
        
    }
}
